package com.nanbei.cas;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @ClassDescription: 自定义原子类
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/10/9 10:34
 */
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        AtomicReference<User> userAtomicReference = new AtomicReference<>();
        User z3 = new User("z3", 22);
        User li4 = new User("li4", 28);
        userAtomicReference.set(z3);
        System.out.println(userAtomicReference.get());
        userAtomicReference.compareAndSet(z3,li4);
        System.out.println(userAtomicReference.get());
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class User{
    String name;
    int age;
}
